<template>
  <el-dialog :width="1300" v-model="visible" @close="cancel">
    <template #title>
      <div class="header">
        <div class="header-title">风险类别</div>
        <div class="header-subTitle">
          {{ info.riskType }}
          <img
            src="@/assets/imgs/spotCheck/y1.png"
            class="grade"
            v-if="info.riskLevel === '一级'"
          />
          <img
            src="@/assets/imgs/spotCheck/y2.png"
            class="grade"
            v-if="info.riskLevel === '二级'"
          />
          <img
            src="@/assets/imgs/spotCheck/y3.png"
            class="grade"
            v-if="info.riskLevel === '三级'"
          />
        </div>
      </div>
    </template>
    <div class="search">
      <MForm
        :fields="fields"
        :col-attrs="24"
        :label-width="200"
        @submit="search"
        @cancel="reset"
      />
    </div>
    <MTable
      :columns="columns"
      :http="handleSortDetail"
      :params="params"
      v-model:isReload="isReload"
      v-model:selectKeys="selectKeys"
      :height="400"
      displayFormat="list"
    >
      <template #状态="{ row }">
        <div class="tag-status" v-if="row.state === 0">
          <span class="warning">待处理</span>
        </div>
        <div class="tag-status" v-if="row.state === 1">
          <span class="pri">已处理</span>
        </div>
      </template>
    </MTable>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from 'vue'
import { fields, columns } from './config'
import { handleSortDetail } from '@/api/spotCheck/spotCheck'

const emit = defineEmits(['reload'])

const visible = ref(false)

const cancel = () => {
  visible.value = false
}

const selectKeys = ref<number[]>([])
const params = ref<any>({})
const isReload = ref(true)
function search(data: any) {
  params.value = {
    ...params.value,
    ...data
  }
}

// 重置
function reset(data: any) {
  params.value = {
    ...params.value,
    ...data
  }
}

// 重置
function reload(data?: any) {
  isReload.value = true
  selectKeys.value = []
}

const info = ref()
const show = (row) => {
  info.value = row
  params.value.riskType = row.riskType
  visible.value = true
}
defineExpose({ show })
</script>

<style scoped lang="scss">
.search {
  display: flex;
  justify-content: space-between;
}
.btns {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 10px 0;
}
.header {
  width: 100%;
  display: flex;
  align-items: center;
  div {
    height: 30px;
    line-height: 30px;
  }
  .header-subTitle {
    margin-left: 20px;
    font-size: 14px;
    color: #0a0a0a;
    font-weight: 300;
    display: flex;
    align-items: center;
    img {
      width: 20px;
      height: 20px;
      margin-left: 10px;
    }
  }
}
</style>
